Allow for nil local-map. Fixes #57
authorjustbur <justin@burkett.cc>
Sat, 1 Aug 2015 11:16:29 +0000 (07:16 -0400)
committerjustbur <justin@burkett.cc>
Sat, 1 Aug 2015 11:16:29 +0000 (07:16 -0400)
which-key.el

index 99d101c99c3ad3a2a8a59beca3eea3e72ca31746..a07f5e2c3bd4fc80015a81cc1587e3b20bffefdd 100644 (file)
@@ -712,6 +712,10 @@ width) in lines and characters respectively."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Functions for retrieving and formatting keys
 
+(defsubst which-key--safe-lookup-key (keymap key)
+  "Version of `lookup-key' that allows KEYMAP to be nil. KEY is not checked."
+  (when (keymapp keymap) (lookup-key keymap key)))
+
 (defun which-key--maybe-replace (string repl-alist &optional literal)
   "Perform replacements on STRING.
 REPL-ALIST is an alist where the car of each element is the text
@@ -796,7 +800,7 @@ alists. Returns a list (key separator description)."
               (desc (cdr key-desc-cons))
               (group (which-key--group-p desc))
               (keys (concat (key-description which-key--current-prefix) " " key))
-              (local (eq (lookup-key local-map (kbd keys)) (intern desc)))
+              (local (eq (which-key--safe-lookup-key local-map (kbd keys)) (intern desc)))
               (key (which-key--maybe-replace
                     key which-key-key-replacement-alist))
               (desc (which-key--maybe-replace
@@ -1142,9 +1146,9 @@ Finally, show the buffer."
                (or
                 (keymapp (key-binding prefix-keys))
                 ;; Some keymaps are stored here like iso-transl-ctl-x-8-map
-                (keymapp (lookup-key key-translation-map prefix-keys))
+                (keymapp (which-key--safe-lookup-key key-translation-map prefix-keys))
                 ;; just in case someone uses one of these
-                (keymapp (lookup-key function-key-map prefix-keys)))
+                (keymapp (which-key--safe-lookup-key function-key-map prefix-keys)))
                (not which-key-inhibit))
       (which-key--create-buffer-and-show prefix-keys))))